package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.RegisterBean;
import com.example.administrator.yuejian2.service.RetrofitService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class RegisterModel {
    private Retrofit retrofit;
    private RetrofitService userService;

    public RegisterModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        userService=retrofit.create(RetrofitService.class);
    }
    public void userRegister(String name,String password,String email,String tel,final RetrofitListener listener)
    {
        Call<RegisterBean> call=userService.register(name,password,email,tel);
        call.enqueue(new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {
                listener.onSuccess(response.body(), 1);
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
